package com.ymatou.iapi.productmanager.testcase.old;

import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.AttachProductToLivesCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.utils.EnvSetup;

import org.json.JSONObject;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.Arrays;
import java.util.List;

@Ignore
public class Ts_AttachProductToLives {
	private static AttachProductToLivesCall attachproducttolivesCall = new AttachProductToLivesCall();
	private static IntergratedProductMapper intergratedProductMapper = SqlMapperFactory.getIntergratedProductMapper();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");	


	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品加入直播");
		intergratedProductMapper.updateProductoffSale(sellerId);
	}

	@Before
	public void caseUp() {
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(attachproducttolivesCall.getOpurl());
	}

	

	@After
	public void caseDown() {
		Logger.end();
	}

	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AttachProductToLives_001() {
		Logger.start(true,"商品加入正在进行直播");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProductOnSale(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			List<Integer> liveIdList = LiveCallService.createLivesInProcessAndInFuture(sellerId, sellerName, 2, 3);
			JSONObject ret = attachproducttolivesCall.call(sellerId, productId,liveIdList);

			for (int i=0;i<liveIdList.size();i++){
				Logger.comment("LiveId:"+ liveIdList.get(i));
				Ts_AddProductInLives.checkAddProductInLive(ret, sellerId,liveIdList.get(i),90000000,Arrays.asList(productId));
			}

		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AttachProductToLives_002() {
		Logger.start(true,"商品加入正在进行直播");
		try {
			Logger.comment("other cases has been test in add productInLives");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
}